﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using DatabaseTool.util;
using SqlSugar;

namespace DatabaseTool
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        
        
        
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            SqlSugarClient db = null;
            try
            {
                db = ClientUtil.GetConnection(ip.Text,username.Text,password.Text,port.Text,schema.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show("数据库连接失败");
            }


            try
            {
                FileInfo file = new FileInfo(dir.Text);
                if (!file.Directory.Exists)
                {
                    MessageBox.Show("该文件夹不存在");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("该文件夹不存在");
            }
            
            Data2Markdown.data2Md(db,dir.Text,schema.Text);
            if (db != null)
            {
                db.Close();
                MessageBox.Show("导出成功");
            }
        }
    }
}